﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMicroblogAPI.HttpRequests;
using AMicroblogAPI.Common;
using AMicroblogAPI;

public partial class Logon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.IsAuthenticated)
        {
            Response.Redirect("./Error.aspx");
        }
    }

    protected void  Logon_Click(object sender, EventArgs e)
    {
        string username = LoginIdTextBox.Text.Trim();
        if (!UserManager.GetInstance().IsUserExist(username))
        {
            Msg.Text = "这个用户还没有注册呢，赶紧注册一个吧";
        }
        else
        {
            global::User user = UserManager.GetInstance().FindUser(username);
            if (!string.Equals(user.Password, PasswordTextBox.Text))
            {
                Msg.Text = "密码不对";
            }
            else
            {
                if (Session["LastUrl"] != null)
                {
                    FormsAuthentication.SetAuthCookie(LoginIdTextBox.Text, Persist.Checked);
                    Response.Redirect(Session["LastUrl"].ToString(), true);
                }
                else
                {
                    FormsAuthentication.RedirectFromLoginPage
                       (LoginIdTextBox.Text, Persist.Checked);
                }
            }
        }

    }

}